from django.db import models
from apps.user.models import User

class MemberLevel(models.Model):
    name = models.CharField(max_length=50, verbose_name='等级名称')
    points_required = models.IntegerField(verbose_name='所需积分')
    discount = models.DecimalField(max_digits=3, decimal_places=2, verbose_name='折扣率')
    
    class Meta:
        verbose_name = '会员等级'
        verbose_name_plural = verbose_name

class MemberPoints(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, verbose_name='用户')
    points = models.IntegerField(default=0, verbose_name='积分')
    level = models.ForeignKey(MemberLevel, on_delete=models.SET_NULL, null=True, verbose_name='等级')
    
    class Meta:
        verbose_name = '会员积分'
        verbose_name_plural = verbose_name 